﻿
using Newtonsoft.Json;
using ProgramCat;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace ComTest
{
    class Program
    {
        static dynamic o = null;
        //private delegate int Delegate_Init();
        static void Main(string[] args)
        {


            System.Type t = Type.GetTypeFromProgID("ProgramCat.AppCom");
            o = Activator.CreateInstance(t);
            //PlugInfos
            string sss = o.LoadAllPlugs(Directory.GetCurrentDirectory());
            List<EPlug> ePlugs = JsonConvert.DeserializeObject<List<EPlug>>(sss);
            foreach (var item in ePlugs)
            {
                Console.WriteLine(item.plugName);
            }
            
            //int plugPtr = ProgramCat.DLLWrapper.LoadSDK(@"C:\Users\unity\Desktop\ProgramCat\ComTest\bin\Release\Scripts\ProgramCat\PlugIn\test.dll");
            //Console.WriteLine(plugPtr);
            //Delegate_Init init = (Delegate_Init)DLLWrapper.GetFunctionAddress(plugPtr, "Init", typeof(Delegate_Init));
            //Console.WriteLine(init);
            //int info = init();
            //Console.WriteLine(Marshal.PtrToStringAnsi((IntPtr)info));
            Console.ReadKey();
        }

        public class EPlug
        {
            /// <summary>
            /// 插件指针
            /// </summary>
            public int plugPtr = 0;
            /// <summary>
            /// 文件名称
            /// </summary>
            public string fileName = "";
            /// <summary>
            /// 插件名称
            /// </summary>
            public string plugName = "";
            /// <summary>
            /// 作者名称
            /// </summary>
            public string plugAuthor = "";
            /// <summary>
            /// 版本号
            /// </summary>
            public string version = "";
        }
    }
}
